package com.anthill.controllers
{
import flash.events.Event;
import flash.events.IEventDispatcher;

import mx.core.FlexGlobals;

/**
 *  EventBus is main Event Dispatcher. This is a base class for 
 *  Сontroller, Events and Managers.
 * 
 */ 
public class EventBus implements IEventDispatcher
{
	include "../Version.as";
	
	/**
     *  Constructor. 
     *  
     */  
	public function EventBus():void
	{
		eventBus = EventBus.eventDispatcher;
	}
	
	/**
	* Top Level Event Dispatcher
	*/
	protected var eventBus:IEventDispatcher;
	
	/**
     *  Static getter for Top Level Event Dispatcher.
     *
     */ 
	static public function get eventDispatcher():IEventDispatcher
	{
		// return top level Event Dispatcher, FlexGlobals used only since Flex 4.
		return FlexGlobals.topLevelApplication as IEventDispatcher;
	}
	
	/**
     *  @private
     */
	public function addEventListener(type:String, listener:Function, useCapture:Boolean=false, priority:int=0, useWeakReference:Boolean=false) : void
	{
		eventBus.addEventListener(type, listener, useCapture, priority, useWeakReference);
	}

	/**
     *  @private
     */
	public function removeEventListener(type:String, listener:Function, useCapture:Boolean=false) : void
	{
		eventBus.removeEventListener(type, listener, useCapture);
	}
	
	/**
     *  @private
     */
	public function dispatchEvent(event:Event) : Boolean
	{
		return eventBus.dispatchEvent(event);
	}
	
	/**
     *  @private
     */
	public function hasEventListener(type:String) : Boolean
	{
		return eventBus.hasEventListener(type);
	} 

	/**
     *  @private
     */
	public function willTrigger(type:String) : Boolean
	{
		return eventBus.willTrigger(type);
	}
}
}